<template>
  <a-modal
    title="查看"
    :width="640"
    :visible="visible"
    @cancel="() => { visible = false }"
  >
    <template slot="footer">
      <a-button type="primary" @click="visible = false">
        关闭
      </a-button>
    </template>
    <a-form v-bind="formLayout" >
      <a-row class="form-row" :gutter="16">
        <a-col :lg="12" :md="24">
          <a-form-item label="上级">
            {{ getName(this.treeData, model.parentId) }}
          </a-form-item>
        </a-col>
        <a-col :lg="12" :md="24">
          <a-form-item label="指标">
            {{ model.target }}
          </a-form-item>
        </a-col>
      </a-row>
      <a-row class="form-row" :gutter="16">
        <a-col :lg="12" :md="24">
          <a-form-item label="排序">
            {{ model.sort }}
          </a-form-item>
        </a-col>
        <a-col :lg="12" :md="24" v-if="model.cj === 4">
          <a-form-item label="序号">
            {{ model.serialNumber }}
          </a-form-item>
        </a-col>
      </a-row>
      <a-row class="form-row" :gutter="16" v-if="model.cj === 4">
        <a-col :lg="12" :md="24">
          <a-form-item label="总分">
            {{ model.totalPoint }}
          </a-form-item>
        </a-col>
        <a-col :lg="12" :md="24">
          <a-form-item label="是否必须">
            {{ model.mustFlag === 0 ? '否' : '是' }}
          </a-form-item>
        </a-col>
      </a-row>
      <a-row class="form-row" v-if="model.cj === 4">
        <a-col :lg="12" :md="24">
          <a-form-item label="说明">
            {{ model.comment }}
          </a-form-item>
        </a-col>
        <a-col :lg="12" :md="24">
          <a-form-item label="备查资料">
            {{ model.backUpData }}
          </a-form-item>
        </a-col>
      </a-row>
      <a-row class="form-row" v-if="model.cj === 4">
        <a-col :lg="12" :md="24">
          <a-form-item label="考核资料">
            <div :key="item.id" v-for="item in model.files">
              <!-- <a :href="item.url" target="_black" :download="item.original">{{ item.original }}</a> -->
              <a @click="$fileDownLoad(item)">{{ item.original }}</a>
            </div>
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </a-modal>
</template>

<script>
export default {
  props: {
    treeData: {
      type: Array,
      default: () => []
    }
  },
  data () {
    this.formLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 13 }
      }
    }
    return {
      visible: false,
      model: {}
    }
  },
  created () {
  },
  deactivated () {
    this.visible = false
  },
  methods: {
    checkView (record) {
      this.visible = true
      this.model = record
    },
    getName (data, id) {
      let target = ''
      for (let i = 0, len = data.length; i < len; i++) {
        if (data[i].id === id) {
          target = data[i].target
          break
        } else if (data[i].childs?.length > 0) {
          target = this.getName(data[i].childs, id)
        }
      }
      return target
    }
  }
}
</script>
